package com.plugin.wukong;

import com.ganide.utils.LogHelp.LogHelp;
import com.ganide.wukit.clibinterface.ClibAirPlugInfo;
import com.ganide.wukit.kits.WukitEventHandler;
import com.ganide.wukit.kits.clibevent.BaseEventMapper;
import com.ganide.wukit.support_devs.airctrl.AirplugKit;
import com.plugin.wukong.SdkDemoApplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import io.ionic.wukong.R;

public class CloudMatchActivity extends Activity implements WukitEventHandler {

    TextView state;
    int handle;
    AirplugKit acKit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cloud_match);

        state = (TextView) findViewById(R.id.state);

        handle = getIntent().getExtras().getInt("handle", 0);

        if (SdkDemoApplication.getKit() instanceof AirplugKit) {
            acKit = (AirplugKit)SdkDemoApplication.getKit();
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        SdkDemoApplication.getKit().registerEvent(BaseEventMapper.SAE_BEGIN, BaseEventMapper.SAE_END, handle, this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        SdkDemoApplication.getKit().unRegisterEvent(BaseEventMapper.SAE_BEGIN, BaseEventMapper.SAE_END, handle, this);
    }

    public void onClickBegin(View v) {
        acKit.acStartCodeMatch(handle, 120);
    }

    public void onClickStop(View v) {
        acKit.acStopCodeMatch(handle);
    }

    public void callback(int skdEvent, int obj_handle, int err_no) {
        switch (skdEvent) {
            case BaseEventMapper.SAE_CODE_MATCH_READY:
                state.setText("ready");
                break;
            case BaseEventMapper.SAE_CODE_MATCH_PROCESS:
                LogHelp.logDebug("xxxddd percent " + err_no);
                state.setText("process  " + err_no + "%");
                break;
            case BaseEventMapper.SAE_CODE_MATCH_OK:
                state.setText("sucess");
                ClibAirPlugInfo info = acKit.acGetInfo(obj_handle);
                LogHelp.logDebug("code match success\n");
                break;
            case BaseEventMapper.SAE_CODE_MATCH_FAILED:
                state.setText("fail");
                break;
            default:
                break;
        }
    }
}
